﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Besture.Common;


namespace Besture.UI.Admin.Dialog
{
    public partial class AdminPageDialog : System.Web.UI.Page
    {
        public string _json = string.Empty;
        //当前类别编号
        public string page = StringHelper.Query("page");

        public string Button = StringHelper.Query("button");

        protected void Page_Load(object sender, EventArgs e)
        {
            page = page.Split('/')[page.Split('/').Length - 1]; 

            //获取目录下的文件
            string path = Server.MapPath("/Admin/");

            StringBuilder Text = new StringBuilder();

            //过滤的文件夹
            List<string> listFilter = new List<string>();
            listFilter.Add("css");
            listFilter.Add("control");
            listFilter.Add("demo");
            listFilter.Add("dialog");
            listFilter.Add("icon");
            listFilter.Add("images");
            listFilter.Add("js");
            listFilter.Add("master");
            listFilter.Add("plugin");
            listFilter.Add("themes");
            
            int id = 0;
            GetFolder(path, ref Text, ref id, listFilter);

            _json = string.Format(@"[{0}];", Text.ToString().TrimEnd(','));
        }



        public void GetFolder(string path, ref StringBuilder text, ref int id, List<string> listFilter)
        {
            DirectoryInfo directoryInfo = new DirectoryInfo(path); 
            DirectoryInfo[] folderInfo = directoryInfo.GetDirectories();

            int idTemp = id;

            //添加文件夹
            for (int i = 0; i < folderInfo.Length; i++)
            {
                id++;
                //过滤掉不相关文件夹
                if (listFilter.Contains(folderInfo[i].Name.ToLower()))
                {
                    continue;
                }
                text.Append("{id:" + id + ", pId:" + idTemp + ", name: '" + folderInfo[i].Name + "',filetype:'1'},");
                GetFolder(folderInfo[i].FullName, ref text, ref id, listFilter);
            }
            //添加文件
            FileInfo[] fileInfo = directoryInfo.GetFiles("*aspx");
            for (int i = 0; i < fileInfo.Length; i++)
            {
                id++;
                text.Append("{id:" + id + ", pId:" + idTemp + ", name: '" + fileInfo[i].Name + "', icon:'/Admin/Themes/Images/aspx.jpg',filetype:'0'},");
            }
        }
    }
}